package com.thd.springboottest.mybatis.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
@Service
@Transactional
public class TransactionTestServiceImpl implements TransactionTestService{
    @Autowired
    private SysUserService sysUserService;
    @Autowired
    private MyUserService myUserService;
    @Autowired
    private SpecialTypeService specialTypeService;
    @Override
    public void testNestedTransaction() {
        myUserService.testNestedTransaction();
        sysUserService.testNestedTransaction();
    }

    @Override
    @Transactional(propagation = Propagation.REQUIRED)
    public void testNewTransaction() {
        myUserService.testNewTransaction(); // 更新任务表状态
        sysUserService.testNewTransaction(); // 执行计算 - 20min

    }

    @Override
    public void testNewTransactionException(){
        myUserService.testNewTransactionException();
        try{
            specialTypeService.testNewTransactionException();
        }catch(Exception e){
            System.out.println("error:" + e.getMessage());
        }
    }
}
